package com.ecfront.test.dao;

import java.util.Date;
import java.util.Iterator;
import java.util.List;

import junit.framework.TestCase;
import com.ecfront.dao.GoodsComplainDAO;
import com.ecfront.pojo.GoodsComplain;
import com.ecfront.pojo.GoodsImpl;
import com.ecfront.pojo.User;

public class testGoodsComplain extends TestCase{
	private static final GoodsComplainDAO goodsComloainDao = (GoodsComplainDAO)SpringUtilTest.getBean("GoodsComplainDAO");
	//save or update test
	public void testSaveOrUpDate(){
		GoodsComplain gc = new GoodsComplain();
		gc.setContent("你们的商品太差了");
		gc.setDate(new Date());
		gc.setSort(0);
		
		User user = new User();
		user.setId(4);
		gc.setUser(user);
		
		GoodsImpl gi = new GoodsImpl();
		gi.setId(1);
		gc.setGoodsImpl(gi);
		
		goodsComloainDao.save(gc);
	}
	//findall test
	public void testFindAll(){
		List list = goodsComloainDao.findAll();
		for(Iterator iter = list.iterator();iter.hasNext();){
			GoodsComplain gc = (GoodsComplain)iter.next();
			System.out.println(gc.getContent());
			
			System.out.println(gc.getGoodsImpl().getGood().getName());
			System.out.println(gc.getUser().getName());
		}
	}
	//finById test
	public void testFindById(){
		GoodsComplain gc = goodsComloainDao.findById(1);
		System.out.println(gc.getContent());
		
		System.out.println(gc.getGoodsImpl().getGood().getName());
		System.out.println(gc.getUser().getName());
	}
	//delete test
	public void testDel(){
		GoodsComplain gc = new GoodsComplain();
		gc.setId(2);
		
		goodsComloainDao.delete(gc);
	}
}
